package com.jservice.framework.dto;

import com.google.common.collect.Maps;
import com.jservice.framework.utils.PropertiesLoader;
import com.jservice.framework.utils.StringUtils;

import java.io.Serializable;
import java.util.Map;

/**
 * Setting - 系统配置
 *
 * @Author cwledit
 * @DATE 2017/4/20.
 */
public class Setting implements Serializable {
	
	private static final long serialVersionUID = -1760847509215819389L;

	private static final String SETTING_FILE = "setting.properties";

    private static Setting setting = new Setting();

    /**
     * 小数位精确方式
     */
    public enum RoundType {

        /** 四舍五入 */
        roundHalfUp,

        /** 向上取整 */
        roundUp,

        /** 向下取整 */
        roundDown
    }

    public enum UserType{
        /** 供应商 */
        supplier,

        /** 订货商 */
        customer
    }

    public enum SupplierType{
        /** 管理员 */
        admin,
        /** 员工 */
        employee
    }

    /**
     * 保存全局属性值
     */
    private static Map<String, String> map = Maps.newHashMap();

    /**
     * 属性文件加载对象
     */
    private static PropertiesLoader loader = new PropertiesLoader(SETTING_FILE);

    /**
     * 获取当前对象实例
     */
    public static Setting getInstance() {
        return setting;
    }

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null){
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return value;
    }

    /** Cookie路径 */
    public static String getCookiePath(){
        return getConfig("cookiePath");
    }

    /** Cookie作用域 */
    public static String getCookieDomain(){
        return getConfig("cookieDomain");
    }

    /** local设置 */
    public static String getLocal(){
        return getConfig("local");
    }

    public static String getUppUrl(){
        return getConfig("upp.url");
    }

    public static String getUppAppId(){
        return getConfig("upp.app_id");
    }

    public static String getUppPrivateKey(){
        return getConfig("upp.private_key");
    }

    public static String getUppPublicKey(){
        return getConfig("upp.public_key");
    }




}
